package com.mooue.controller;

import com.fresh.common.ResponseResult;
import com.mooue.entity.Supplier;
import com.mooue.service.SupplierService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 供应商表结构(Supplier)表控制层
 *
 * @author bsciology
 * @since 2023-08-11 15:05:39
 */
@RestController
@RequestMapping("supplier")
public class SupplierController {
    /**
     * 服务对象
     */
    @Resource
    private SupplierService supplierService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<Supplier> queryById(@PathVariable("id") Integer id) {
        return new ResponseResult<>(200, "ok", this.supplierService.queryById(id));
    }


    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping()
    public ResponseResult<List<Supplier>> queryById() {
        return new ResponseResult<>(200, "ok", this.supplierService.queryAll());
    }


    /**
     * 新增数据
     *
     * @param supplier 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseResult<Supplier> add(Supplier supplier) {
        return new ResponseResult<>(200, "ok", this.supplierService.insert(supplier));
    }

    /**
     * 编辑数据
     *
     * @param supplier 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseResult<Supplier> edit(Supplier supplier) {
        return new ResponseResult<>(200, "ok", this.supplierService.update(supplier));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseResult<Boolean> deleteById(Integer id) {
        return new ResponseResult<>(200, "ok", this.supplierService.deleteById(id));
    }

}

